//
//  TabBarController.m
//  CYTabBarDemo
//
//  Created by 张春雨 on 2017/11/17.
//  Copyright © 2017年 张春雨. All rights reserved.
//

#import "TabBarController.h"
#import "PlusAnimate.h"
#import "TZImagePickerController.h"
#import "SDAutoLayout.h"
//#import "FuctionView.h"

@interface TabBarController ()<CYTabBarDelegate>

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _popView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    //_popView.backgroundColor = [[UIColor blackColor]  colorWithAlphaComponent:0.5];
    _popView.hidden = true;
    _popView.backgroundColor = UIColor.whiteColor;
    _popView.userInteractionEnabled = YES;
    [_popView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapevent:)]];
    
    
}
//点击任意关闭
- (void)tapevent:(UITapGestureRecognizer *)gesture {
    _popView.hidden = true;
    [_popView removeFromSuperview];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabbar.delegate = self;
}
//功能点击事件
-(void)functionClick:(long)tag{
    
}

#pragma mark - CYTabBarDelegate
//中间按钮点击
- (void)tabbar:(CYTabBar *)tabbar clickForCenterButton:(CYCenterButton *)centerButton{
    //[PlusAnimate standardPublishAnimateWithView:centerButton];
    CGRect rect= centerButton.imageView.frame;
    //[self.view sendSubviewToBack:_popView];
    
    if(_popView.isHidden){
        _popView.hidden = false;
        UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
        [keyWindow addSubview:_popView];
    }else{
        _popView.hidden = true;
        [_popView removeFromSuperview];
        
    }
    
    UIButton *centerBtn = [CYCenterButton buttonWithType:UIButtonTypeCustom];
    centerBtn.adjustsImageWhenHighlighted = NO;
    //centerBtn.frame = rect;
    centerBtn.backgroundColor = UIColor.whiteColor;
    [centerBtn setImage:[centerButton imageForState:UIControlStateNormal] forState:UIControlStateNormal];
    
    [_popView addSubview:centerBtn];
    centerBtn.sd_layout.centerXEqualToView(_popView).bottomSpaceToView(_popView, -(rect.size.height - 20)).widthIs(rect.size.width).heightIs(rect.size.height);
    centerBtn.layer.cornerRadius = rect.size.height/2;
    centerBtn.layer.masksToBounds = YES;
}
//是否允许切换
- (BOOL)tabBar:(CYTabBar *)tabBar willSelectIndex:(NSInteger)index{
        NSLog(@"将要切换到---> %ld",index);
    return YES;
}
//通知切换的下标
- (void)tabBar:(CYTabBar *)tabBar didSelectIndex:(NSInteger)index{
        NSLog(@"切换到---> %ld",index);
        _popView.hidden = true;
        [_popView removeFromSuperview];
}

@end
